package com.zq.zqmanager.controller;

import com.alibaba.fastjson.JSONObject;
import com.zq.zqmanager.service.QuartzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: zqmanager
 * @Date: 2020/3/9 8:37
 * @Author: zhengqiang
 * @Description:
 */
@RestController
public class QuartzController {

    @Autowired
    private QuartzService quartzService;

    @RequestMapping("/addQuartz")
    public String addQuartz(){
        JSONObject json = this.getParams();
        this.quartzService.add(json.toJSONString());
        return "success";
    }

    @RequestMapping("/delQuartz")
    public String delQuartz(){
        JSONObject json = this.getParams();
        this.quartzService.delete(json.toJSONString());
        return "delSuccess";
    }

    @RequestMapping("/modifyQuartz")
    public String modifyQuartz(String cron){
        JSONObject json = this.getParams();
        if(cron!=null&&!cron.equals("")) {
            json.put("cron",cron);
        }
        this.quartzService.modify(json.toJSONString());
        return "modifySuccess";
    }

    public JSONObject getParams(){
        JSONObject json = new JSONObject();
        json.put("jobName","myjob");
        json.put("jobGroupName","myjobgroup");
        json.put("triggerName","mytrigger");
        json.put("triggerGroupName","mytriggergroup");
        json.put("cron","0/5 * * * * ?");
        return json;
    }

}
